import axios from "axios";

export const baseApi = {
  // 获取活动设置（单活动模式）
  getSettings: () => axios.get("/index/settings"),
  // 保存活动设置（单活动模式）
  saveSettings: (data) => axios.post("/activity/settings", data),
};

export const prizeApi = {
  // 获取活动奖品列表
  getList: () => axios.get("/prize/list"),

  // 创建奖品
  create: (data) => axios.post("/prize/save", data),

  // 更新奖品
  update: (id, data) => axios.put(`/prize/save`, { id, ...data }),

  // 删除奖品
  delete: (id) => axios.delete(`/prize/delete`, { params: { id } }),
};

export const userApi = {
  // 获取所有用户
  list: (params) =>
    axios.get("/user/list", {
      params: params,
    }),
  // 获取未中奖用户
  userlist: () => axios.get("/user/list"),

  // 获取已中奖用户
  getWinners: (params) =>
    axios.get("/user/list", {
      params: {
        is_winner: 1,
        page: params.page || 1,
        pagesize: params.pagesize || 20,
      },
    }),
  // 获取未中奖用户
  getNonWinners: (params) =>
    axios.get("/user/list", {
      params: {
        is_winner: 0,
        page: params.page || 1,
        pagesize: params.pagesize || 20,
      },
    }),

  // 保存中奖用户
  saveLucky: (data) => axios.post(`/user/savelucky`, data),

  // 创建用户
  create: (data) => axios.post("/user/create", data),

  // 更新用户
  update: (id, data) => axios.put(`/user/${id}`, data),

  // 删除用户
  delete: (id) => axios.delete(`/user/${id}`),

  // 批量导入用户
  batchImport: (count) => axios.get("/user/batchCreate", { params: { count } }),

  // 清空所有用户
  clearAll: () => axios.delete("/user/clear-all"),
};

export const drawApi = {
  // 抽奖
  draw: (round) => axios.post("/draw", { round }),

  // 获取抽奖记录
  getRecords: (params) =>
    axios.get("/draw/records", {
      params: {
        page: params.page || 1,
        pagesize: params.pagesize || 20,
      },
    }),

  // 获取指定轮次的抽奖记录
  getRecordsByRound: (round) => axios.get(`/draw/records/round/${round}`),

  // 重置抽奖
  reset: () => axios.post("/draw/reset"),
};

// 默认导出
export default {
  baseApi,
  prizeApi,
  userApi,
  drawApi,
};
